package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.ShoppingCart;
import com.itheima.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;


    //展示购物车
    @GetMapping("/list")
    public R<List<ShoppingCart>> shoppingCartList(@RequestHeader("AuthorizationUser") String token ){
        log.info("展示用户购物车token={}",token);
        return shoppingCartService.clientShoppingCartList(token);
    }

    //添加购物车
    @PostMapping("/add")
    public R<ShoppingCart> addShoppingCart(@RequestBody ShoppingCart shoppingCart){
        log.info("添加购物车信息shoppingCart={}",shoppingCart);
        return shoppingCartService.clientAddShoppingCart(shoppingCart);
    }


    @PostMapping("/sub")
    public R<ShoppingCart> subShoppingCart(@RequestBody ShoppingCart shoppingCart){
        log.info("减少的购物车信息shoppingCart={}",shoppingCart);
        return shoppingCartService.clientSubShoppingCart(shoppingCart);

    }

    @DeleteMapping("/clean")
    public R<String> shoppingCartClean(@RequestHeader("AuthorizationUser") String token){
        log.info("清空购物车通过token={}",token);
        return shoppingCartService.clientShoppingCartClean(token);
    }









}
